const BehaviorAll = require("../../../behaviors/behavior_all.js");
const Tool = require("../../../utils/tool.js");
const ServiceUser = require("../../../service/service_user.js");
const ServiceBranchCompany = require("../../../service/service_branchCompany");

Component({
  /**
   * behaviors
   */
  behaviors: [BehaviorAll],
  /**
   * 页面的初始数据
   */
  data: { 
    /** 用户相关 */
    userAmount: 0,  // 用户金额
    userInfo: null, // 用户数据
    /** 提现相关 */
    withdrawOrderList:[],
    /**
     * 状态
     * 0 全部
     * 1 未通过
     * 2 完成
     */
    state:0,
    /**
     * 开始页
     */
    startPage: 0
  },
  /**
   * 组件的方法列表
   */
  methods: {
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      const _this = this;
      // 获取金额
      ServiceBranchCompany.getMoney(function (data) {
        _this.setData({ userAmount: data })
      });
      // 获取提现列表
      ServiceBranchCompany.withdrawVerifingPage(0, _this.data.state, function (data) {
        _this.setData({ withdrawOrderList: data.records });
      });
      ServiceUser.getInfo(function (data) {
        _this.setData({ userInfo: data })
      });
    },
    /**
     * 切换tab
     */
    onTab: function (e) {
      const _this = this;
      const state = Number(e.currentTarget.dataset.state);
      ServiceBranchCompany.withdrawVerifingPage(0, state, function (data) {
        _this.setData({
          startPage: 0,
          state:state,
          withdrawOrderList: data.records
        });
      });
    },
    onPass: function(e){
      const _this = this;
      const id = e.currentTarget.dataset.id;
      ServiceBranchCompany.withdrawVerifyPass(id, function(data){
        // 获取提现列表
        ServiceBranchCompany.withdrawVerifingPage(0, _this.data.state, function (data) {
          _this.setData({ 
            startPage: 0,
            withdrawOrderList: data.records 
          });
        });
      });
    },
    onNopass: function(e){
      const _this = this;
      const id = e.currentTarget.dataset.id;
      ServiceBranchCompany.withdrawVerifyNoPass(id, function(data){
        // 获取提现列表
        ServiceBranchCompany.withdrawVerifingPage(0, _this.data.state, function (data) {
          _this.setData({ 
            startPage: 0,
            withdrawOrderList: data.records 
          });
        });
      });
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
      const _this = this;
      let startPage = _this.data.startPage + 1;
      // 获取提现列表
      ServiceBranchCompany.withdrawVerifingPage(startPage, _this.data.state, function (data) {
        _this.data.withdrawOrderList.push(...data.records);
        _this.setData({ 
          startPage: startPage,
          withdrawOrderList: _this.data.withdrawOrderList
        });
      });
    }

  }
})
